﻿//======================================================================
//
//        Copyright (C) 苏州逸仙软件    
//        All rights reserved
//
//        filename :D_T_KnowledgeExp
//        description :知识点信息扩展类
//
//        created by Jason at  2010-12-13 17：49
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using huaguwang;
using System.Data.SqlClient;
using System.Data;


namespace huaguwang
{
    public class D_T_Knowledge_Exp : D_T_Knowledge
    {
        /// <summary>
        /// 分页获取数据量
        /// </summary>
        /// <returns></returns>
        public int GetPageCount(string title,string cate)
        {
           string strSQL = ExpandMSSQL.GetPageSQL(
               "T_Knowledge a inner join T_Category b on a.CateID = b.id inner join T_AdminUser c on a.UserID = c.id",
               "a.flag =1 and b.flag =1 and a.Title like '%'+@title+'%'");
            if (cate!="")
            {
                strSQL = strSQL + " and a.CateID ='" + cate + "'";
            }
            SqlParameter[] parms = { 
                                   new SqlParameter("@title",SqlDbType.NVarChar,100)
                                   };
            parms[0].Value = title.Exp_Trim();
            var PageCount = MSSQLHelper.SQLConType.C1.Exp_GetSingle(strSQL,parms).Exp_IntTryParse();
            return PageCount;
        }

        /// <summary>
        /// 分页获取数据信息
        /// </summary>
        /// <param name="Begin">起始目录</param>
        /// <param name="Size">每页显示的数量</param>
        /// <returns></returns>
        public List<M_T_Knowledge_Exp.clsFind> GetPageList(int Begin, int Size, string title, string cate)
        {
          StringBuilder strwhere = new StringBuilder();
          strwhere.Append("a.flag =1 and b.flag =1 and a.Title like '%'+@title+'%'");
          if (cate !="")
          {
              strwhere.Append(" and a.CateID ='" + cate + "'");
          }
         string strSQL = ExpandMSSQL.GetPageSQL(
                Begin,
                Size,
                "a.id,a.Title,a.AddDate,a.Contents,a.Topis,a.RemSign,b.CateName,c.RealName",
                "T_Knowledge a inner join T_Category b on a.CateID = b.id inner join T_AdminUser c on a.UserID = c.id",
                "a.id",
               strwhere.ToString(),
                "a.AddDate desc");
            SqlParameter[] parms = { 
                                   new SqlParameter("@title",SqlDbType.NVarChar,100)
                                   };
            parms[0].Value = title.Exp_Trim();
            var List =MSSQLHelper.SQLConType.C1.Exp_GetList(strSQL,
                DR => new M_T_Knowledge_Exp.clsFind()
                {
                    id =DR["id"].Exp_IntTryParse(),
                    Title = DR["Title"].Exp_Trim().Exp_SubStringByLength(34,""),
                    AddDate =DR["AddDate"].Exp_DateTimeTryParse(),
                    Contents  =DR["Contents"].Exp_Trim().Exp_SubStringByLength(38,""),
                    CateName  =DR["CateName"].Exp_Trim().Exp_SubStringByLength(14,""),
                    RemSign =DR["RemSign"].Exp_BoolTryParse()?"推荐":"不推荐",
                    Topis = DR["Topis"].Exp_IntTryParse()==1? "置顶" : "不置顶",
                    UserName =DR["RealName"].Exp_Trim()
                },parms);
            return List;
        }         
    }
}
